package cn.xing.async;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;

import cn.xing.util.JedisAdapter;
import cn.xing.util.RedisKeyUtil;
/**
 * 事件分发，生产者
 * @author Xing
 *
 */
@Service
public class EventProducer {
	@Autowired
	JedisAdapter jedisAdapter;

	public boolean fireEvent(EventModel model) {
		try {
			System.out.println("事件生产者开始生产-==========================================");
			String json = JSONObject.toJSONString(model);//序列化
			String key = RedisKeyUtil.getEventQueueKey();
			jedisAdapter.lpush(key, json);//List，双端链表，将事件从左边推进去
			return true;
		} catch (Exception e) {
			return false;
		}
	}
}
